using System.Collections.Generic;
using System.Linq;
using game_config;

namespace game_stuff
{
    public class OtherPassiveStatus
    {
        private float PassiveLvDmgAdd { get; set; }
        private float PassiveKindDmgDec { get; set; }

        private float DamageResist { get; set; }

        private uint NowPassiveMaxLv { get; set; }
        private uint NowPassiveMaxKind { get; set; }

        public OtherPassiveStatus()
        {
            PassiveLvDmgAdd = 0;
            PassiveKindDmgDec = 0;
            DamageResist = 0f;
            NowPassiveMaxLv = 0;
            NowPassiveMaxKind = 0;
        }

        public void WhenPickAPassive(Dictionary<passive_id, PassiveTrait> passiveTraits)
        {
            var enumerable = passiveTraits.Values.Where(xx =>
                CommonConfig.Configs.passives[xx.PassId].passive_effect_type != passive_type.OtherPassive
                && CommonConfig.Configs.shop_passive_unlocks.Values.Any(xxx => xxx.passive_id == xx.PassId)
            ).ToArray();
            var max = enumerable.Any() ? enumerable.Max(x => x.Level) : 0;
            var passiveTraitsCount = enumerable.Length;
            NowPassiveMaxLv = max;
            NowPassiveMaxKind = (uint)passiveTraitsCount;
        }

        public float GetDamageDecMulti()
        {
            return NowPassiveMaxKind * PassiveKindDmgDec + DamageResist;
        }

        public float GetDamageAddMulti()
        {
            return PassiveLvDmgAdd * NowPassiveMaxLv;
        }

        public void Refresh(float[] vector)
        {
            PassiveLvDmgAdd = vector[0];
            PassiveKindDmgDec = vector[1];
            DamageResist = vector[2];
        }
    }
}